 
<?php



require 'php-sdk/src/facebook.php';


// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array(
  'appId'  => '176213615761250',
  'secret' => '375110a154f2a4f5b2f6e4f8f093f7be',
));

// Get User ID
$user = $facebook->getUser();



if ($user) {
  try {
    // Proceed knowing you have a logged in user who's authenticated.
    //$user_profile = $facebook->api('/me');
	$user_profile = $facebook->api('/me');
	//echo $user_profile['name'];
	//echo "<br>";
	$friends = $facebook->api('/me/friends');
// 	$id = $friends['data'][0]['id'];
// 	echo $id;
	foreach ($friends as $key=>$value) {
		$x = count($value);
	}
// 		echo '<hr />';
// 		echo '<ul id="friends">';
		$random=rand(0, $x);
// 		foreach ($value as $fkey=>$fvalue) {
// 			echo $fvalue;
			echo '<img src="https://graph.facebook.com/' . $friends['data'][$random]['id'] . '/picture" title="' . $friends['data'][$random]['name'] . '"/>' . $friends['data'][$random]['name'] . ' ';
// 		}
		//echo '</ul>';
	
//  	print_r($friends);
  } catch (FacebookApiException $e) {
    error_log($e);
    $user = null;
    echo "An error occured! Try again!<br><br> $e";
  }
}
else {
	$loginUrl = $facebook->getLoginUrl();
	echo "<a href=" . $loginUrl . ">Login with Facebook</a>";
}

// echo $_GET["jsoncallback"] . "({\"Message\":\"" . $Message . "\"})";
?>
